﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data.OleDb;
using System.Data.Sql;
using System.Data.SqlClient;
using System.Collections;
using System.Data;
using DTO;
using DAO;

namespace BUS
{
    public class VoBinhGasBUS
    {
        public static void DoiVo(int voDoi, int voNhan, int soLuong)
        {
            OleDbConnection conn = DataAccess.OpenOleConnection();
            OleDbTransaction trans = conn.BeginTransaction();
            try
            {
                VoBinhGasDAO.GiamSoLuong(trans, voDoi, soLuong);
                VoBinhGasDAO.TangSoLuong(trans, voNhan, soLuong);
                trans.Commit();
                conn.Close();
            }
            catch (Exception ex) {
                trans.Rollback();
                conn.Close();
                throw;
            }
        }
        public static void BanVo(int loaiGas, int soLuong)
        {
            OleDbConnection conn = DataAccess.OpenOleConnection();
            OleDbTransaction trans = conn.BeginTransaction();
            try
            {
                VoBinhGasDAO.GiamSoLuong(trans, loaiGas, soLuong); 
                trans.Commit();
                conn.Close();
            }
            catch (Exception ex)
            {
                trans.Rollback();
                conn.Close();
                throw;
            }
        }
        public static void MuaVo(int loaiGas, int soLuong)
        {
            OleDbConnection conn = DataAccess.OpenOleConnection();
            OleDbTransaction trans = conn.BeginTransaction();
            try
            {
                VoBinhGasDAO.TangSoLuong(trans, loaiGas, soLuong);
                trans.Commit();
                conn.Close();
            }
            catch (Exception ex)
            {
                trans.Rollback();
                conn.Close();
                throw;
            }
        }
    }
}
